import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
	current_page : number;
	result ?: any;
	per_page ?: number;
	total ?: number;
	data ?: any;
};
type ResultDelete = {
	code : number;
	msg : string;
};
type ResultCreate = {
	code : number;
	msg : string;
};
type Show = {
	code : number;
	msg : string;
	result ?: any;
};
/** 物料列表 */
export const getMaterialListApi = (params ?: object) => {
	return http.request<Result>("get", "/material/list", {
		params
	});
};

/** 物料添加*/
export const createMaterialApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/material/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料修改 */
export const updateMaterialApi = (data ?: object) => {
	return http.request<ResultCreate>("put", "/material/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料删除 */
export const delMaterialApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", "/material/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料详情 */
export const getMaterialShowApi = (params ?: object) => {
	return http.request<Show>("get", "/material/show", {
		params
	});
};
/** 物料状态更新 */
export const updateStatusMaterialApi = (params ?: object) => {
	return http.request<ResultCreate>("put", "/material/updateStatus", {
		params
	}).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 单位列表 */
export const getMaterialUnitListApi = (params ?: object) => {
	return http.request<Result>("get", "/materialUnit/list", {
		params
	});
};

/** 单位添加*/
export const createMaterialUnitApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/materialUnit/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 单位修改 */
export const updateMaterialUnitApi = (data ?: object) => {
	return http.request<ResultCreate>("put", "/materialUnit/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 单位删除 */
export const delMaterialUnitApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", "/materialUnit/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 单位详情 */
export const getMaterialUnitShowApi = (params ?: object) => {
	return http.request<Show>("get", "/materialUnit/show", {
		params
	});
};
/** 单位状态更新 */
export const updateStatusMaterialUnitApi = (params ?: object) => {
	return http.request<ResultCreate>("put", "/materialUnit/updateStatus", {
		params
	}).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 物料类型列表 */
export const getMaterialCategoryListApi = (params ?: object) => {
	return http.request<Result>("get", "/materialCategory/list", {
		params
	}).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 物料类型添加*/
export const createMaterialCategoryApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/materialCategory/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料类型修改 */
export const updateMaterialCategoryApi = (data ?: object) => {
	return http.request<ResultCreate>("put", "/materialCategory/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料类型删除 */
export const delMaterialCategoryApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", "/materialCategory/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料类型详情 */
export const getMaterialCategoryShowApi = (params ?: object) => {
	return http.request<Show>("get", "/materialCategory/show", {
		params
	});
};
/** 物料类型状态更新 */
export const updateStatusMaterialCategoryApi = (params ?: object) => {
	return http.request<ResultCreate>("put", "/materialCategory/updateStatus", {
		params
	}).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料类型选择 */
export const selectMaterialCategoryApi = (params ?: object) => {
	return http.request<Result>("get", "/materialCategory/select", {
		params
	});
};
/**
 * 
 * 物料上架
 * 
 * */ 
/** 物料上架*/
export const createWarehouseProductApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/warehouseProduct/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料详情 */
export const getMaterialShowByNumberApi = (params ?: object) => {
	return http.request<Show>("get", "/material/showByCode", {
		params
	}).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料上架列表 */
export const getWarehouseProductListApi = (params ?: object) => {
	return http.request<Result>("get", "/warehouseProduct/list", {
		params
	});
};
/**
 * 
 * 物料下架
 * 
 * */ 
/** 物料下架*/
export const createExtractApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/warehouseProduct/extract", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 物料下架列表 */
export const getDispatchOrderListApi = (params ?: object) => {
	return http.request<Result>("get", "/warehouseProductFlowlog/list", {
		params
	});
};